package ro.msg.quiz.validator;

import ro.msg.quiz.domain.Question;
import ro.msg.quiz.domain.TextQuestion;
import ro.msg.quiz.exception.MyException;

//AUTHORS: Elod, Marco

//Class that validates a TextQuestion
public class TextQuestionValidator extends QuestionValidator {

    @Override
    public void validate(Question o) throws MyException {
	StringBuilder sb = new StringBuilder();
	if (o instanceof TextQuestion) {
	    TextQuestion q = (TextQuestion) o;
	    if (q.getAnswer() == "")
		sb.append("The question doesn't have a correct answer!");
	} else
	    sb.append("The object is not an instance of TextQuestion!\n");

	if (sb.length() > 0) {
	    throw new MyException(sb.toString());
	}
    }

}
